package com.jxmcloud.business.cut.service.impl.database;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jxmcloud.business.cut.mapper.database.IUserTurnDBMapper;
import com.jxmcloud.business.cut.model.database.DBUserTurntable;
import com.jxmcloud.business.cut.service.database.IUserTurntableDBService;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service
public class UserTurntableDBServiceImpl extends ServiceImpl<IUserTurnDBMapper, DBUserTurntable> implements IUserTurntableDBService {

    @Override
    public DBUserTurntable loadData(Integer uid, Integer activityId) {
        QueryWrapper<DBUserTurntable> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("uid", uid);
        queryWrapper.eq("activity_id", activityId);
        return baseMapper.selectOne(queryWrapper);
    }

    @Override
    public boolean insertData(DBUserTurntable dbData) {
        return baseMapper.insert(dbData) > 0;
    }

    @Override
    public boolean updateData(DBUserTurntable dbData) {
        return this.lambdaUpdate()
                .set(Objects.nonNull(dbData.getTurnData()),DBUserTurntable::getTurnData,dbData.getTurnData())
                .set(Objects.nonNull(dbData.getTurnData()),DBUserTurntable::getAwardList,dbData.getAwardList())
                .set(Objects.nonNull(dbData.getTurnData()),DBUserTurntable::getPoolId,dbData.getPoolId())
                .eq(DBUserTurntable::getUid,dbData.getUid())
                .eq(DBUserTurntable::getActivityId,dbData.getActivityId())
                .update();
    }
}
